package com.api.shopapi.mapper;


import com.api.shopapi.entity.Area;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AreaMapper {

    @Insert("insert into area(AreaCode,ParentAreaCode,Name,Sort,Level,Status) values " +
            "(#{area.AreaCode},#{area.ParentAreaCode},#{area.Name},#{area.Sort}," +
            "#{area.Level},#{area.Status})")
    int insert(@Param("area") Area area);


    @Delete("delete from area where areaCode=#{areaCode}")
    int deleteByAreaCode(@Param("areaCode") String areaCode);


    @Update("update area set Name=#{area.Name},Sort=#{area.Sort}," +
            "Level=#{area.Level},Status=#{area.Status}" +
            " where AreaCode=#{area.AreaCode}")
    int updateByAreaCode(@Param("area") Area area);


    @Select("select * from area where areaCode=#{areaCode} limit 1")
    Area getByAreaCode(@Param("areaCode") String areaCode);


    @Select("select * from area")
    List<Area> getList();

    @Select("select * from area where parentAreaCode=#{parentAreaCode} order by Sort desc")
    List<Area> getListByParentAreaCode(String parentAreaCode);

}
